package product.configuration;


import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@EnableConfigurationProperties(ThreadConfigProperties.class)
@Configuration
public class MyThreadConf {


    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadConfigProperties threadConfigProperties) {
        return new ThreadPoolExecutor(
                threadConfigProperties.getCoreSize(),
                threadConfigProperties.getMaxSize(),
                threadConfigProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
